/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   13-4-14 下午4:21 Created by dwzhang
 */
package com.jade.framework.base.criterion.expression;

import com.jade.framework.base.criterion.Constants;
import com.jade.framework.base.criterion.Criterion;
import com.jade.framework.base.util.SimpleParameters;
import org.apache.commons.lang3.StringUtils;

/**
 * 查询条件，用于搜素引擎的搜索。支持通配符.
 *
 * @author dwzhang
 * @version 1.0 13-4-14 下午4:21
 */
public class QueryStringExpression extends SimpleParameters implements Criterion
{
    /** 需要搜索的属性 */
    private String[] fields;
    /** 查询文本，支持 this AND that OR other模式 */
    private String query;
    /** 默认操作 */
    private String defaultOperator = Constants.OR;
    /** 查询分本分词器 */
    private String analyzer;
    /** 是否使用词组 */
    private boolean phrase;
    /** 是否支持在查询文本中使用通配符 */
    private boolean allowWildcard;

    public QueryStringExpression(String query, String[] fields)
    {
        this.query = query;
        this.fields = fields;
    }

    public String[] getFields()
    {
        return fields;
    }

    public void setFields(String[] fields)
    {
        this.fields = fields;
    }

    public String getQuery()
    {
        return query;
    }

    public void setQuery(String query)
    {
        this.query = query;
    }

    public String getDefaultOperator()
    {
        return defaultOperator;
    }

    public void setDefaultOperator(String defaultOperator)
    {
        this.defaultOperator = defaultOperator;
    }

    public String getAnalyzer()
    {
        return analyzer;
    }

    public void setAnalyzer(String analyzer)
    {
        this.analyzer = analyzer;
    }

    public boolean isPhrase()
    {
        return phrase;
    }

    public void setPhrase(boolean phrase)
    {
        this.phrase = phrase;
    }

    public boolean isAllowWildcard()
    {
        return allowWildcard;
    }

    public void setAllowWildcard(boolean allowWildcard)
    {
        this.allowWildcard = allowWildcard;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("QueryString(");
        sb.append(StringUtils.join(fields, ',')).append(" ");
        sb.append("[").append(query).append("]").append(" ");
        sb.append(defaultOperator).append(" ");
        sb.append(analyzer).append(" ");
        sb.append(phrase).append(" ");
        sb.append(allowWildcard);
        sb.append(")");
        return sb.toString();
    }
}
